<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>仓库管理</title>
</head>
<body>
<style>
	* {
		font-size: 12px;
	}
	
	.yzr-storehouse-item{
		margin-top: 5px;
	}
</style>


<script type="text/javascript">
	$(function(){
		//打开添加药房的窗口
		$("#yzr-storehouse-add").linkbutton({onClick: function(){
			$('#yzr-storehouse-window').window({'title': "录入仓库"});
			$('#yzr-storehouse-form').form("clear");
			$("#yzr-storehouse-window").window("open");
		}});
		
		//提交添加/编辑药房的请求
		$("#yzr-storehouse-btnok").linkbutton({onClick: function(){
			var title = $('#yzr-storehouse-window').window("options").title;
			var url = (title == '录入仓库' ? 'addStorehouse' : 'editStorehouse');
			$('#yzr-storehouse-form').form('submit', {
				url: url,
			    onSubmit: function(){
			    	return $(this).form("validate");
			    },
			    success:function(data){
			    	var json = eval("(" + data + ")");
					$.messager.alert("提示", json.reason);
					$('#yzr-storehouse-window').window('close');
					$("#tb-storehouse").datagrid("reload");
					$(this).form("clear");
			    }
			});
		}});
		
		//打开编辑药房的窗口
		$("#yzr-storehouse-edit").linkbutton({onClick: function(){
			var rows = $("#tb-storehouse").datagrid("getSelections");
			if(rows.length == 1){
				$('#yzr-storehouse-window').window({'title': "编辑仓库"});
				$('#yzr-storehouse-window').window("open");
				var sId = rows[0].storeId;
				$.getJSON("queryStorehouseById", {"sId": sId}, function(data){
					$("#yzr-storehouse-form").form("load", data);
					$("#yzr_storehouse_staff").combogrid({value: data.staffNo});
				});
				
			}else{
				$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
			}
			
		}});
		
		//批量删除
		/* $("#yzr-storehouse-delete").linkbutton({onClick: function(){
			var rows = $("#tb-storehouse").datagrid("getSelections");
			if(rows.length >= 1){
				$.messager.confirm("提示", "确定要删除吗？", function(v){
					if(v){
						var rows = $("#tb-storehouse").datagrid("getSelections");
						var arr = [];
						for(var i = 0; i < rows.length; i ++){
							arr.push(rows[i].storeId);
						}
						$('<form>').form('submit', {
						    url:'delStorehouse',
						    onSubmit: function(param){
						    	param.list = arr;
						    },
						    success:function(data){
						    	var json = eval("(" + data + ")");
								$.messager.alert("提示", json.reason);
								$("#tb-storehouse").datagrid("reload");
						    }
						});
					}
				});
			}else{
				$.messager.alert("提示", "至少选择一条记录，您目前选择了" + rows.length + "条!");
			}
		}}); */
		
		//显示全部
		$("#yzr-storehouse-reload").linkbutton({onClick:function(){
			$("#tb-storehouse").datagrid({
	    		url: 'queryAllStorehouse', 
	    		method: 'get'
	    	});
			
		}});
		
		//根据名称模糊查询药房 
		$('#yzr-storehouse-search').searchbox({
		    searcher:function(value,name){
		    	if(value == ''){
		    		$.messager.alert("提示", "请输入查询条件！");
		    	}else{
		    		$("#tb-storehouse").datagrid({
			    		url: 'queryStorehouseByName', 
			    		method: 'post', 
			    		queryParams: {
			    			storeName: value
			    	}});
		    		$('#yzr-storehouse-search').searchbox('setValue', '');
		    	}		    	
		    }
		});
		
		
	});
</script>




	<table id="tb-storehouse" class="easyui-datagrid" 
		data-options="url:'queryAllStorehouse',
			fitColumns:true,
			fit:true,
			striped:true,
			pagination: true,
			pageSize: 10,
			pageList: [10, 20, 30, 40],
			rownumbers: true,
			toolbar: '#yzr-storehouse-tb',
			border:false
			">
		<thead>
			<tr>		
				<th data-options="field:'XXX',width:'4%',checkbox:true">仓库编号</th>	
				<th data-options="field:'storeId',width:'20%',align:'center'">仓库编号</th>			
				<th data-options="field:'storeName',width:'20%',align:'center'">仓库名称</th>
				<th data-options="field:'staffName',width:'13%',align:'center'">负责人</th>
				<th data-options="field:'storeKind',width:'15%',align:'center'">仓库类型</th>
				<th data-options="field:'storeArea',width:'12%',align:'center'">仓库面积</th>
				<th data-options="field:'storeAddress',width:'18%',align:'center'">仓库地址</th>		
			</tr>
		</thead>
	</table>
	
	<div id="yzr-storehouse-tb">
		<a id="yzr-storehouse-add" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加仓库</a>
		<a id="yzr-storehouse-edit" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改仓库</a>
		<!-- <a id="yzr-storehouse-delete" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">删除药房</a> -->
		<a id="yzr-storehouse-reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
		<input id="yzr-storehouse-search" class="easyui-searchbox" data-options="menu: '#yzr-storehouse-name', width: 220, prompt: '请输入仓库名称关键字'"/>
	</div> 
	
	<div id="yzr-storehouse-name" style="width:120px">
	    <div data-options="name:'name'">仓库名称</div>
	</div>
	
	<!-- 添加/修改药房窗口 -->
	<div id="yzr-storehouse-window" class="easyui-window" title="录入药房" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:400px;height:320px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="yzr-storehouse-form" method="post">
					<div class="yzr-storehouse-item" style="display:none;"><input name="storeId" class="easyui-textbox"  data-options="label: '仓库编号', width: 280,readonly:true"></div>
					<div class="yzr-storehouse-item"><input name="storeName" class="easyui-textbox" data-options="label: '仓库名称', width: 220, required:true"></div>					
					<div class="yzr-storehouse-item">
						<select  id="yzr_storehouse_staff" name="storeChargeperson" class="easyui-combogrid" style="width:200px;"
						    data-options="
						    label: '负责人',
						    panelWidth:240,
						    idField:'staffNo',
						    textField:'staffName',
						    url:'queryAllStaff',
						    required:true,
						    columns:[[
						    {field:'staffName',title:'员工名称',width:80},
						    {field:'departmentName',title:'科室',width:80},
						    {field:'postName',title:'职务',width:60}
						    ]]
						    "></select>
					</div>
					<div class="yzr-storehouse-item">
						<select class="easyui-combobox" name="storeKind" data-options="label: '仓库类型', width: 200, required:true,panelHeight:65">
						    <option value="药品供应">药品仓库</option>
						    <option value="器械供应">器械仓库</option>
						    <option value="耗材供应">耗材仓库</option>
						</select>
					</div>
					<div class="yzr-storehouse-item"><input name="storeArea" class="easyui-textbox" data-options="label: '仓库面积', width: 180, required:true"></div>
					<div class="yzr-storehouse-item"><input name="storeAddress" class="easyui-textbox" data-options="label: '仓库地址', width: 250, required:true"></div>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="yzr-storehouse-btnok" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true" >确定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#yzr-storehouse-window').window('close');" onclick="">取消</a>
			</div>
		</div>
	</div>
</body>
</html>